package com.itsitio.registeradmin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itsitio.registeradmin.dao.BranchDao;
import com.itsitio.registeradmin.dao.CompanyDao;
import com.itsitio.registeradmin.dao.CompanyTypeDao;
import com.itsitio.registeradmin.dto.CompanyDTO;
import com.itsitio.registeradmin.model.Company;
import com.itsitio.registeradmin.model.CompanyType;
import com.itsitio.registeradmin.service.CompanySrv;

@Service
public class CompanySrvImpl implements CompanySrv{

	@Autowired
	private CompanyDao companyDao;
	
	@Autowired
	private BranchDao branchDao;
	
	@Autowired
	private CompanyTypeDao typeDao;
	
	
	
	public Company getCompanyById(Integer companyId){
		return companyDao.obtener(companyId);
	}
	
	public List<Company> getCompanyListByCriteria(String firmName,
			String taxId, String tradeName) {
		 
		return companyDao.getCompanyListByCriteria(firmName,
				taxId, tradeName);
		
	}

	public List<Company> getCompanyListByTaxId(String taxId) {
		return companyDao.getCompanyListByTaxId(taxId);
	}

	public List<CompanyDTO> getCompanyDtoListByCriteria(String companyTaxId, String firmName) {
		return companyDao.getCompanyDtoListByCriteria(companyTaxId, firmName);
	}

	//@Override
	public void updateCompanyWithUserRegistrationData(Integer selectedCompany,
			String firmName, String tradeName, Integer type, String website,
			String taxId) {
		Company company = companyDao.obtener(selectedCompany);
		CompanyType companyType = typeDao.obtener(type);
		
		company.setWebsite(website);
		company.setTradeName(tradeName);
		company.setTaxId(taxId);
		company.setFirmName(firmName);
		company.setCompanyType(companyType);
		
		companyDao.guardar(company);
		
		
	}

	//@Override
	public Company createCompanyFromUserRegistration(String firmName,
			String tradeName, Integer type, String website, String taxId) {
		Company company = new Company();
		CompanyType companyType = typeDao.obtener(type);
		
		company.setWebsite(website);
		company.setTradeName(tradeName);
		company.setTaxId(taxId);
		company.setFirmName(firmName);
		company.setCompanyType(companyType);
		
		companyDao.guardar(company);
		return company;
		
	}

}
